
#include "stdafx.h"
#include "VideoServer.h"
#include "DSocket.h"
#include "VideoServerDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DSocket

// Initialize static members...
unsigned char DSocket::vdata[30000];
unsigned int DSocket::vlength=30000;

DSocket::DSocket()
{
#if 0
	strcpy(remoteaddress, "192.168.0.100");
#else
	strcpy(remoteaddress, "127.0.0.1");
#endif
}

DSocket::~DSocket()
{
}

/////////////////////////////////////////////////////////////////////////////
// DSocket member functions

void DSocket::CreateSocket(int port)
{
	this->Create(port,SOCK_DGRAM);
	gethostname(localname,300);
}


void DSocket::SetParent(CDialog *dlg)
{
	pdlg=dlg;	
}

void DSocket::OnReceive(int errcode)
{
	CString address;
	unsigned int port,retvalue;

	retvalue=this->ReceiveFrom(vdata,vlength,address,port);
	if(retvalue==SOCKET_ERROR)		return;

	return;

}

void DSocket::SendVideoData(unsigned char *data,int length)
{
	Sleep(100);
	SendTo(data,length,PEER_PORT_VIDEO,remoteaddress);	
}

void DSocket::CloseSocket()
{
	DSocket::Close();
}
